<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html >
<html>
<head>
<title><spring:message code="message.lable.compinfoSTDmerge"/></title>
<%@ include file="/WEB-INF/component/commonCSS.jsp" %>
<script src="${ctx}/lib/js/JOrderInfo.js" type="text/javascript"></script>
<!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
<style type="text/css">
body {
	font-family: "Lucida Grande", Tahoma, Verdana, Lucida, Arial, Helvetica,
		sans-serif, "宋体";
	font-size: 12px;
}

#process {
	margin: 50px;
	padding: 25px 0 80px;
}

#process .node, #process .proce {
	float: left;
	position: relative;
	height: 18px;
	background-image: url(${ctx}/lib/img/bg_state.jpg);
	background-repeat: no-repeat;
}

#process .node.ready {
	width: 13px;
	background-position: -150px 0px;
}

#process .node.doing {
	width: 13px;
	background-position: -150px -60px;
}

#process .node.wait {
	width: 13px;
	background-position: -150px -40px;
}

#process .proce {
	width: 150px;
}

#process .proce.doing {
	background-position: 0 -20px;
	color: #360;
}

#process .proce.wait {
	background-position: 0 -40px;
	color: #360;
}

ul {
	display: inline-block;
	list-style: none;
}

#process ul {
	padding-top: 18px; /*margin-left: -152px;*/
	margin-left: -190px;
	display: inline-block;
	margin-top: 0px;
	position: absolute;
	width: 314px;
	text-align: center;
	list-style: none;
}

#process .proce ul {
	z-index: 5;
	width: 150px;
}

#process .node ul {
	z-index: 1;
	width: 275px;
	margin-left: -125px;
}

#Logistics li {
	padding: 5px 0px;
}

#process .tx2 {
	color: #999;
	line-height: 15px;
}

#OrderInfo {
	margin: 5px;
	border: 0px;
	width: 95%;
}

#OrderInfo th {
	background-color: #FFFCEB;
	text-align: right;
	width: 120px;
}

#OrderInfo td {
	text-align: left;
}

#processexplain div {
	float: right;
	height: 18px;
	background-image: url(${ctx}/lib/img/bg_state.jpg);
	background-repeat: no-repeat;
	padding-left: 16px;
	margin-right: 20px;
}
/*增加，否则ie6有问题*/
* html #process .node {
	background-position-x: -150px;
}

* html #process .proce {
	background-position-x: 0;
}

* html #process .wait {
	background-position-y: -40px;
}

* html #process .doing {
	background-position-y: -20px;
}

* html #process .ready {
	background-position-y: 0;
}

* html #process .singular {
	background-position-y: -60px;
}
/*ff*/
#process .node ul {
	z-index: 1;
	width: 200px;
	margin-left: -125px;
}
/* ie8+*/
#process .node ul {
	z-index: 1\9;
	width: 200px\9;
	margin-left: -125px\9;
}
/*ie6 7 特殊处理*/
#process .node ul {
	*z-index: 1;
	*width: 200px;
	*margin-left: -90px;
}
/*google*/
@media screen and (-webkit-min-device-pixel-ratio:0) {
	#process .node ul {
		z-index: 1;
		width: 200px;
		margin-left: -125px;
	}
}
</style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
	<section class="content-header">
	<h1><spring:message code="message.lable.compinfoSTDmerge"/></h1>
	<ol class="breadcrumb">
		<li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.StdManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.compinfoStd"/></a></li>
	</ol>
	</section>

		<section class="content">
			<div class="box box-success">
           		<div class="box-header with-border">
               	 	<h3 class="box-title"><spring:message code="message.lable.beiHeBing"/><spring:message code="message.list.compinfoStdMergelist"/></h3>
               	 	<div class="box-tools pull-right">
                	</div>
           		 </div>
           	 
            <div class="box-header  ">
			<div class="form-group form-group-xs">
                        <label for="exampleInputEmail1" class="col-sm-2 text-right"><spring:message code="message.listForm.qiYeBianMa"/>：</label>
                        <div class="col-sm-2 text-left">${list.compCode }</div>
                        <label for="exampleInputEmail1" class="col-sm-2 text-right"><spring:message code="message.listForm.qiYeMingCheng"/>：</label>
                        <div class="col-sm-2 text-left">${list.compName }</div>
                        <label for="exampleInputEmail1" class="col-sm-2 text-right"><spring:message code="message.listForm.zuZhiJiGouDaiMa"/>：</label>
                        <div class="col-sm-2 text-left">${list.orgCode }</div>
                    </div>
                    </div>
                    <div class="box-header  with-border">
                    <div class="form-group form-group-xs">
                        
                        <label for="exampleInputEmail1" class="col-sm-2 text-right"><spring:message code="message.listForm.qiYeShuXing"/>：</label>
                        <div class="col-sm-2 text-left">${list.compType==1?"生产企业":"经营配送企业"}</div>
                        <label for="exampleInputEmail1" class="col-sm-2 text-right"><spring:message code="message.listForm.suoShuDiQu"/>：</label>
                        <div class="col-sm-2 text-left">${list.dicArea.arfullname }</div>
                        <label for="exampleInputEmail1" class="col-sm-2 text-right"><spring:message code="message.listForm.qiYeZhuCeLeiXing"/>：</label>
                        <div class="col-sm-2 text-left">${list.dicCompType.compRegName }</div>
                    </div>
                    <div class="form-group form-group-xs">
                    </div>
            </div>
     	</div>   
        
		<div class=" box box-success">
            <div class="box-body">
            
                <div class="input">
                    <div class="textalign1"><spring:message code="message.listForm.qiYeMingCheng"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="compName" name="compName" placeholder="<spring:message code="message.listForm.qiYeMingCheng"/>"/>
                    </div>
                    
                    <div class="textalign"><spring:message code="message.listForm.qiYeBianMa"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="compCode" name="compCode" placeholder="<spring:message code="message.listForm.qiYeBianMa"/>"/>
                    </div>
                    
                    <div class="textalign"><spring:message code="message.listForm.qiYeLeiXing"/>：</div>
                    <div class="boxinput">
                        <select  class="textinput" id="selectId" name="compType">
                            <option value=""><spring:message code="message.select.option"/></option>
                            <option value="1"><spring:message code="message.listForm.shengChanQiYe"/></option>
                            <option value="2"><spring:message code="message.model.peiSongQiYe"/></option>
                        </select>
                    </div>
                </div>
           <div class="input" style="margin-top:-5px">
                    <div class="textalign1"><spring:message code="message.listForm.qiYeZhuCeLeiXing"/>：</div>
                    <div class="boxinput">
                          <table style="width:100%;">
                                 <tr>
                                        <td style="width:100%">
                                          <select class="textinput" id="compRegId" name="compRegId1"></select>
                                        </td>
                                       
                                </tr>              
                          </table>   
                     </div>
                     <div class="textalign"><spring:message code="message.listForm.suoShuDiQu"/>：</div>
                     <div class="boxinput">
                           <table style="width:100%;">
                               <tr>
                                  <td style="width:33%">
                                    <select class="textinput" id="area1" name="area1"></select>
                                  </td>
                                  <td style="width:33%">   
                                    <select class="textinput" id="area2" name="area2"></select>
                                    </td>
                                  <td style="width:33%">
                                    <select class="textinput" id="area3" name="area3"><option value=''><spring:message code="message.select.option"/></option></select>
                                  </td>
                               </tr> 
                            </table>
                      </div>
                       <div class="textalign1" >
                           <button id="selectMerge" type="button" onclick="likeQuery();" class="btn btn-success btn-sm"><spring:message code="message.button.seachSpacing"/></button>
                     </div> 
                </div>
          
            </div>
        </div>

	
	<table class="jqgrid" id="gridlist"></table>
		<div id="gridpage"></div>
		<div class=" box box-warning bottongroup">
			<button type="button" onclick="merge()"class="btn btn-default btn-sm"><spring:message code="message.button.combineSpacing"/></button>
			<button type="button" onclick="window.location.href='javascript:history.go(-1)'"class="btn btn-default btn-sm"><spring:message code="message.button.getBackSpacing"/></button>
		</div>
		<form action="${ctx}/stdCompinfo/toStdCompinfoDetailJsp.html"id="FormDetail" method="post">
			<input type="hidden" name="compCodeDetail" id="compCodeDetail" /> 
		</form>
	</section>
	<%@ include file="/WEB-INF/component/commonJS.jsp" %>
	<script type="text/javascript">
	
	 //绑定回车
    $('#selectId,#area1,#area2,#area3,#compRegId,#compCode,#compName').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectMerge').click();
        }
    }); 
  
    $("#compName").focus();//加载页面光标在第一个查询框内
	
		$(function() {
			$('#addNew').click(function() {
				$('#exampleModal').modal({
					keyboard : true
				});
			});
			 $("#area1").HNSelect({
		            url: "${pageContext.request.contextPath}/selectController/getArea.html", data: { ID: '000000' },  defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
		            func: function () {
		                $("#area2").HNSelect({
		                    parent_selector: "#area1", url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID",defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
		                    		  func: function () {
		                                  $("#area3").HNSelect({
		                                      parent_selector: "#area2", url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID", defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
		                                  });
		                              }
		                });
		            }
		        });
			  $("#compRegId").HNSelect({
		            url: "${pageContext.request.contextPath}/selectController/getDicCompType.html", data: {compRegId:""},  defaultText: "<option value=''><spring:message code="message.select.option"/></option>"
		        });
			  
			
			$("#gridlist").jqGrid({
                url: "${ctx}/stdCompinfoDetail/toMergeDataList.html",
                mtype: "post",
                datatype: "json",
                postData: {"compId" : "${list.compId}"},
                autowidth: true,
                //shrinkToFit: false,
                height: 270,
                colNames: ['compId',
                           '<spring:message code="message.listForm.qiYeBianMa"/>', 
                           '<spring:message code="message.listForm.qiYeMingCheng"/>',
                           '<spring:message code="message.listForm.qiYeLeiXing"/>',
                           '<spring:message code="message.listForm.zuZhiJiGouDaiMa"/>',
                           '<spring:message code="message.listForm.suoShuDiQu"/>', 
                           '<spring:message code="message.listForm.qiYeZhuCeLeiXing"/>',
                           '<spring:message code="message.lable.status"/>'],
                colModel: [
							{ name: 'compId', width: 100,align:"center" ,hidden:true,sortable: false},
							{ name: 'compCode', width: 180,align:"center" ,sortable: false},
							{ name: 'compName', width: 190,align:"left",sortable: false,
		                    	formatter:function(val, opts, rowdata) {
		      						 return "<a href=\"javascript:$.HN.dialog.opendialog('"+rowdata.compId+"','"+val+"','${ctx}/stdCompinfo/toStdCompinfoDetail.html?compId="+rowdata.compId+"','800px','400px',function operResult(val){return operResult;})\">"+val+"</a>";
		      		     	}   },
							{ name: 'compType', width: 80,align:"center",sortable: false,
								formatter : function(val, opts,
										rowdata) {
									var str = "";
									if (rowdata.compType == 1) {
										str = "<spring:message code="message.listForm.shengChanQiYe"/>";
									}
									if (rowdata.compType == 2) {
										str = "<spring:message code="message.model.peiSongQiYe"/>";
									}
									return str;
								}
								},
							{ name: 'orgCode', width: 100,align:"center",sortable: false },
                            { name: 'dicArea.arfullname', width: 60,align:"center",sortable: false },
                            { name: 'dicCompType.compRegName', width: 120,align:"center",sortable: false },
                            { name: 'status',width: 40,align:"center",sortable: false ,
                            	cellattr:function (rowId, val, rawObject, cm) {
                                    if(val == '停用'){
                                        return 'style="color:red"';
                                    }
                                },
                            	formatter : function(val, opts, rowdata) {
                                	var strStatu = "";
                           			if (rowdata.status == 1){
                           				strStatu += "<spring:message code="message.button.start"/>";
                           			} else if (rowdata.status == 2){
                           				strStatu += "<spring:message code="message.button.stop"/>"
                           			}
                                	return strStatu;
                            } }
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect : true,
                viewrecords: true,
                gridComplete: function(){
                	var page = $("#gridlist").jqGrid('getGridParam','page');
            		var rows = $('#gridlist').getGridParam("rowNum");
            		var maxnum = (rows*page).toString();
            		var len = (maxnum.length)*10;
            		$('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
                	$('#gridlist_rn').css('width',len+'px');
                	
                	//单条数据自动选中
                	var rowIds = $("#gridlist").jqGrid('getDataIDs');
                	if(rowIds.length==1){
                		$("#"+rowIds[0]).click();
                	}
                },
                caption: "<spring:message code="message.list.compinfoStdMergelist"/>",
                jsonReader: {
                    repeatitems: false,
                    id: "ids"
                }
            });
			$("#gridlist").jqGrid('navGrid', '#gridpage', {add : false,edit : false,del : false,search : false,refresh : false});
			$(window).trigger("resize");
		});

		function getNumChekBox(cellvalue, options, rowObject) {
			var str = "<input type=\"text\" name=\"drug\" value=\"\" />";
			return str;
		}
		function addAdress() {
			$('#exampleModal').modal({
				keyboard : true
			});
		}
		function editAdress() {
			$('#editAddr').modal({
				keyboard : true
			});
		}
		function manageAdress() {
			$('#manageAddr').modal({
				keyboard : true
			});
		}
		
		
		//合并
		function merge(){
		 var compIdMerge = "${list.compId}";
				var checked = false;
				$("input.cbox").each(function() {
					if ($(this).is(":checked")) {
						checked = true;
						return false;
					};
				});

				if (!checked) {
					$.alert("<spring:message code="message.lable.pleaseSelect"/><spring:message code="message.button.combine"/><spring:message code="message.lable.de"/><spring:message code="message.list.compinfoStdMergelist"/>！", "warn");
				} else {
					var rowIds = $("#gridlist").jqGrid('getGridParam', 'selarrrow');
					var compId = "";
					var rowdata = $("#gridlist").jqGrid('getRowData', rowIds);
					compId = rowdata.compId;
					
					var data = "";
					for(var i = 0;i<rowIds.length;i++){
						var sta =  $("#gridlist").jqGrid('getRowData',rowIds[i]);
						var compName = sta.compName;
						data += $(compName).html()+",";
					}
					$.HN.message.confirm('<spring:message code="message.lable.OKYES"/><spring:message code="message.button.combine"/><spring:message code="message.lable.yiXia"/><spring:message code="message.list.compinfoStdMergelist"/><spring:message code="message.lable.ma"/><br/>'+data, '', '').on(function(e) {
						if (e) {
							var list = [];
							for (var i=0; i<rowIds.length; i++) {
								rowId = rowIds[i];
								var rowdata = $("#gridlist").jqGrid('getRowData',rowId);
								list.push({"status":3, "compId": rowdata.compId,"compIdMerge":rowdata.compId,"start":"<spring:message code="message.button.combine"/>"});
							}
							$.post("${ctx}/stdCompinfo/batchChangeStatus.html", {
								"array" : json.jsonToString(list)
							}, function(result) {
								if (result.success) {
									$.alert("<spring:message code="message.HN.alert.chengGong"/><spring:message code="message.button.combine"/>"+list.length+"<spring:message code="message.lable.tiao"/>！", "success");
									window.location.href="${ctx}/stdCompinfo/stdCompinfoListJsp.html";
								} else {
									$.alert(result.msg || "<spring:message code="message.button.combine"/><spring:message code="message.HN.alert.shibai"/>！", "error");
								}
							}, "json");
					            }
						});
					}
				}
		//查询
		function likeQuery() {
			var compType = $("#selectId").val();
			var areaId = "";
			if( "" != $("#area1").val() ){
				areaId = $("#area1").val();
			}
			if( "" != $("#area2").val()){
				areaId = $("#area2").val();
			}
			if( "" != $("#area3").val()){
				areaId = $("#area3").val();
			}
			var compRegId = $("#compRegId").val();
			var compCode = $("#compCode").val();
			var compName = $("#compName").val();
			$("#gridlist").jqGrid('setGridParam',{
								url : "${pageContext.request.contextPath}/stdCompinfoDetail/toMergeDataList.html",
				       	    	datatype:'json',
				                postData:{
				                	"compType":compType,
				                	"areaId":areaId,
				                	"compRegId":compRegId,
				                	"compCode":compCode,
				                	"compName":compName},
				                page : 1
							}).trigger("reloadGrid");
		}
		
		function detail(compCode){
			$("#compCodeDetail").val(compCode);
			$("#FormDetail").submit();
		}
	</script>
</body>
</html>